#include <stdio.h>


int removeElement(int* nums, int numsSize, int val) {
    int front=0,rear=numsSize-1,tmp;
    while( front <= rear ){
        while( front < numsSize && nums[front] != val){
            front++;
        }
        while( rear >= 0 && nums[rear] == val ){
            rear--;
        }
        if( front < rear ){
            nums[front++]=nums[rear];
            nums[rear--]=val;
        }
    }
    return front;
}

int main(){
    int a[]={0,1,2,2,3,0,4,2};
    int n=removeElement(a,sizeof(a)/sizeof(int),2);
    for(int i=0;i<n;i++)
        printf("%d ",a[i]);
    return 0;
}
